/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.biz.domain;

import com.alibaba.fastjson.annotation.JSONField;
import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiModelProperty;
import cn.hutool.core.bean.copier.CopyOptions;
import javax.persistence.*;
import javax.validation.constraints.*;
import javax.persistence.Entity;
import javax.persistence.Table;

import lombok.Getter;
import lombok.Setter;
import me.zhengjie.modules.biz.domain.HazardousChemicalsTotal;
import me.zhengjie.modules.system.domain.Job;
import me.zhengjie.modules.system.domain.User;
import org.hibernate.annotations.*;
import java.sql.Timestamp;
import java.io.Serializable;
import java.util.Set;

/**
* @website https://eladmin.vip
* @description /
* @author Admin
* @date 2023-03-23
**/
@Entity
@Getter
@Setter
@Table(name="hj_project")
public class Project implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "`id`")
    @ApiModelProperty(value = "id")
    private Integer id;

    @Column(name = "`name`",nullable = false)
    @NotBlank
    @ApiModelProperty(value = "项目名称")
    private String name;

    @Column(name = "`desc`")
    @ApiModelProperty(value = "项目描写")
    private String desc;

    @Column(name = "`creator_id`")
    @ApiModelProperty(value = "创建人")
    private Integer creatorId;

    @Column(name = "`created_at`")
    @CreationTimestamp
    @ApiModelProperty(value = "createdAt")
    private Timestamp createdAt;

    @Column(name = "`updated_at`")
    @UpdateTimestamp
    @ApiModelProperty(value = "updatedAt")
    private Timestamp updatedAt;

//    @ManyToMany(fetch = FetchType.EAGER)
//    @ApiModelProperty(value = "项目耗材")
//    @JoinTable(name = "hj_project_hazardous_chemicals",
//            joinColumns = {@JoinColumn(name = "project_id")},
//            inverseJoinColumns = {@JoinColumn(name = "name")},
//            inverseJoinColumns = {@JoinColumn(name = "type")}
//    )
//    private Set<HazardousChemicalsTotal> HazardousChemicalsTotals;

//    @ManyToMany(fetch = FetchType.EAGER)
//    @ApiModelProperty(value = "项目人员")
//    @JoinTable(name = "hj_project_user",
//            joinColumns = {@JoinColumn(name = "project_id")},
//            inverseJoinColumns = {@JoinColumn(name = "user_id")})
//    private Set<User> users;

    @JSONField(serialize = false)
    @ManyToMany(mappedBy = "projects")
    @ApiModelProperty(value = "菜单角色", hidden = true)
    private Set<User> users;

    public void copy(Project source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}
